<?php

class Quad_Data_Aba extends Quad_Data_Abstract {
	
	public function __construct($no = '') {
		$this->raw = $no;
		$this->number = trim(preg_replace('/\D/', '', $no));
	}
	
	public static function create($no) {
		return new self($no);
	}
	
	public function isValid() {
		// http://www.brainjar.com/js/validation/
		if (strlen($this->number) != 9 || $this->number == '000000000') {
			return false;
		}
		$d = str_split($this->number);
		$sum = (
			($d[0] * 3) + ($d[1] * 7) + ($d[2] * 1) +
			($d[3] * 3) + ($d[4] * 7) + ($d[5] * 1) +
			($d[6] * 3) + ($d[7] * 7) + ($d[8] * 1)
		);
		return (($sum % 10) == 0);		
	}

	public function format() {
		return $this->number;
	}
		
}